package com.misolab.game.sbh.data.pref;

import android.content.Context;
import android.content.SharedPreferences;

public class PreferUtil {
	
	public static final String PREF = "Pref";

	public static String getPreferences(Context context, String name, String key, String defValue) {
		if (context == null) {
			return "";
		}
		return context.getSharedPreferences(name, Context.MODE_PRIVATE).getString(key, defValue);
	}

	public static boolean setPreferences(Context context, String name, String key, String value) {
		if (context == null) {
			return false;
		}
		SharedPreferences pref = null;
		pref = context.getSharedPreferences(name, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = pref.edit();
		editor.putString(key, value);
		return editor.commit();
	}

	public static int getPreferencesInt(Context context, String name, String key) {
		if (context == null) {
			return 0;
		}
		return context.getSharedPreferences(name, Context.MODE_PRIVATE).getInt(key, 0);
	}

	public static boolean setPreferencesInt(Context context, String name, String key, int value) {
		if (context == null) {
			return false;
		}
		SharedPreferences pref = null;
		pref = context.getSharedPreferences(name, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = pref.edit();
		editor.putInt(key, value);
		return editor.commit();
	}

	
	public static boolean setPreferences(Context context, String key, String value) {
		return setPreferences(context, PREF, key, value);
	}

	public static String getPreferences(Context context, String key) {
		return getPreferences(context, PREF, key, "");
	}

	
	
	public static boolean setPreferencesInt(Context context, String key, int value) {
		return setPreferencesInt(context, PREF, key, value);
	}

	public static int getPreferencesInt(Context context, String key) {
		return getPreferencesInt(context, PREF, key);
	}
}